<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Zixun extends CI_Controller {

	function __construct(){
		parent::__construct();
		$this->load->model('production_model');
		$this->load->model('zixun_model');
	}
	public function action()
	{
		$data['success'] = $this->session->flashdata('success');
		$data['error'] = $this->session->flashdata('error');
		$id = (int)$this->uri->segment(3);
		if(!$id) show_error('错误的操作');

		$p = $this->production_model->get_production_byid($id);
		if(!$p) show_error('该商品可能已经被删除');
		
		$data['p'] = $p;
		$this->load->library('form_validation');
		$this->form_validation->set_rules('content', '咨询内容', 'trim|required|xss_clean');
		if($this->form_validation->run()){
			$r = $this->zixun_model->action($id);
			if($r['status']){
				$this->session->set_flashdata('success','发表咨询成功！');
			}
			else{
				$this->session->set_flashdata('error',$r['msg']);
			}
			redirect(current_url(),'reflash');
		}
		$start = $this->uri->segment(5,0);
		$point_type = (int)$this->uri->segment(4,1);
		if($id == 1 && $point_type == 1){
			$data['c'] = $this->zixun_model->get_zixun($id,$point_type,$start,PAGENUM +10);
			$data['num'] = $this->zixun_model->get_zixun_num($id,$point_type);

			//pagenation
			$this->load->library('pagination');
			$config['base_url'] = '/zixun/action/' . $id . '/' . $point_type . '/';
			$config['total_rows'] = $data['num'];
			$config['per_page'] = PAGENUM + 10; 
			$config['full_tag_open'] = '<p class="page">';
			$config['full_tag_close'] = '</p>';
			$config['uri_segment'] = 5;
			$config['first_link'] = '首页';
			$config['last_link'] = '尾页';
			$config['cur_tag_open'] = '<b>';
			$config['cur_tag_close'] = '</b>';
			$config['next_link'] = '下一页';
			$config['prev_link'] = '上一页';
			$this->pagination->initialize($config); 
			$data['page'] = $this->pagination->create_links();
		}else{
			$this->load->model('rese_model');
			$data['rese'] = $rese = $this->rese_model->get_rese_bypid($id);
			foreach($rese as $rs){
				switch($rs->type){
					case 'zf':$data['zf'] = $rs;break;
					case 'ps':$data['ps'] = $rs;break;
					case 'ss':$data['ss'] = $rs;break;
					case 'cj':$data['cj'] = $rs;break;
				}
			}
		}
		
		$data['point_type'] = $point_type;

		$this->load->view('zixun.tpl',$data);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */